"""
测试图表生成器功能
"""
from tools.juyuan_tools.utils.chart_generator import generate_html_content


def test_chart_generation():
    # 测试数据
    # test_data = [
    #     {"基金名称": "基金A", "净值": 1.2, "规模": 1000000, "收益率": 0.05},
    #     {"基金名称": "基金B", "净值": 1.5, "规模": 2000000, "收益率": 0.08},
    #     {"基金名称": "基金C", "净值": 1.1, "规模": 1500000, "收益率": 0.03},
    #     {"基金名称": "基金D", "净值": 1.8, "规模": 3000000, "收益率": 0.12},
    #     {"基金名称": "基金E", "净值": 1.3, "规模": 800000, "收益率": 0.06}
    # ]
    test_data = [
        {"基金名称": "华夏成长混合", "净值": 1.235, "规模(亿元)": 125.8, "收益率": "5.7%"},
        {"基金名称": "易方达蓝筹精选", "净值": 2.418, "规模(亿元)": 328.5, "收益率": "8.3%"},
        {"基金名称": "嘉实新兴产业", "净值": 1.892, "规模(亿元)": 89.3, "收益率": "4.2%"},
        {"基金名称": "富国天惠成长", "净值": 3.156, "规模(亿元)": 215.7, "收益率": "9.6%"},
        {"基金名称": "景顺长城鼎益", "净值": 2.734, "规模(亿元)": 178.2, "收益率": "6.7%"},
        {"基金名称": "汇添富价值精选", "净值": 1.978, "规模(亿元)": 142.6, "收益率": "7.4%"},
        {"基金名称": "广发稳健增长", "净值": 1.543, "规模(亿元)": 95.4, "收益率": "5.1%"},
        {"基金名称": "中欧医疗健康", "净值": 2.891, "规模(亿元)": 267.9, "收益率": "8.8%"}
    ]
    
    # # 测试柱状图生成
    # bar_chart_options = generate_chart(test_data, ChartType.BAR, "基金规模对比")
    # print("柱状图配置:", bar_chart_options)
    #
    # # 测试饼图生成
    # pie_chart_options = generate_chart(test_data, ChartType.PIE, "基金规模占比")
    # print("饼图配置:", pie_chart_options)
    #
    # # 测试折线图生成
    # line_chart_options = generate_chart(test_data, ChartType.LINE, "基金收益率趋势")
    # print("折线图配置:", line_chart_options)
    #
    # # 测试自动图表类型检测
    # auto_chart_options = generate_chart(test_data, title="自动图表类型")
    # print("自动图表配置:", auto_chart_options)


    # 测试html报告生成
    html_content = generate_html_content(test_data, "html报告", "html报告")
    print("html报告:", html_content)

    with open('report.html', 'w', encoding='utf-8') as f:
        f.write(html_content)

    print("文件已保存为 report.html，请用浏览器打开")


if __name__ == "__main__":
    test_chart_generation()